<?php
class Paging {
    public function getArrPaging($currPage, $numberPage, $limitPage = 1) {
		// get start & and page
		$startPage = 1;
		$endPage = $numberPage;
		if ($numberPage > 10) {
			$startPage = $currPage - 5;
			$endPage = $currPage + 4;
			if ($startPage <= 0) {
				$startPage = 1;
				$endPage = 10;
			}
			if ($endPage > $numberPage) {
				$startPage = $numberPage - 9;
				$endPage = $numberPage;
			}
		}
		// get array page for smarty
		$arrPage = array();
		for ($i = $startPage; $i < $endPage + 1; $i++) {
			$arrPage[] = $i;
		}
		return $arrPage;
	}
	
	public function getStrPaging($arrPage, $currPage, $numberPage, $arrParam = null, $flag = false) {
	 	// String Paging
		//$strPaging = $currPage."/".$numberPage;
		$strPaging = '';
		if (is_array($arrPage) && count($arrPage) != 0) {
			if ($arrPage[0] == $currPage) {
				$strPaging .= $arrPage[0];
			} else {
				$strPaging .= '<a href="index.php?';
				foreach($arrParam as $key => $value) {
				     $strPaging .= $key . "=" . $value . "&";
				}
				if($flag) {
					$strPaging .= 'pageNo=' . $arrPage[0] . '#content">' . $arrPage[0] ."</a>";
				} else {
					$strPaging .= 'pageNo=' . $arrPage[0] . constants::$pathUrl . '">' . $arrPage[0] ."</a>";
				}
			}
			for ($i = 1; $i < count($arrPage); $i++) {
				$strPaging .= "&nbsp;|&nbsp;";
				if ($arrPage[$i] == $currPage) {
					$strPaging .= $arrPage[$i];
				} else {
					$strPaging .= '<a href="index.php?';
					foreach($arrParam as $key => $value) {
				     	$strPaging .= $key . "=" . $value . "&";
					}
					if ($flag) {
						$strPaging .= 'pageNo=' . $arrPage[$i] . '#content">' . $arrPage[$i] ."</a>";
					} else {
						$strPaging .= 'pageNo=' . $arrPage[$i] . constants::$pathUrl . '">' . $arrPage[$i] ."</a>";
					}
				}
			}
	 	}
		return $strPaging;
	}
	
	public function getStrPagingHistory($arrPage, $currPage, $numberPage, $arrParam = null, $flag = false) {
	 	// String Paging
		//$strPaging = $currPage."/".$numberPage;
		$strPaging = '';
		if (is_array($arrPage) && count($arrPage) != 0) {
			if ($arrPage[0] == $currPage) {
				$strPaging .= $arrPage[0];
			} else {
				/*$strPaging .= '<a href="index.php?';
				foreach($arrParam as $key => $value) {
				     $strPaging .= $key . "=" . $value . "&";
				}
				if($flag) {
					$strPaging .= 'pageNo=' . $arrPage[0] . '#content">' . $arrPage[0] ."</a>";
				} else {
					$strPaging .= 'pageNo=' . $arrPage[0] . constants::$pathUrl . '">' . $arrPage[0] ."</a>";
				}*/
				$strPaging .= "<a href='".WEB_LINK."/product/page-lich-su-mua-hang-".$arrPage[0]."#content'>".$arrPage[0]."</a>"; 
			}
			for ($i = 1; $i < count($arrPage); $i++) {
				$strPaging .= "&nbsp;|&nbsp;";
				if ($arrPage[$i] == $currPage) {
					$strPaging .= $arrPage[$i];
				} else {
					/*$strPaging .= '<a href="index.php?';
					foreach($arrParam as $key => $value) {
				     	$strPaging .= $key . "=" . $value . "&";
					}
					if ($flag) {
						$strPaging .= 'pageNo=' . $arrPage[$i] . '#content">' . $arrPage[$i] ."</a>";
					} else {
						$strPaging .= 'pageNo=' . $arrPage[$i] . constants::$pathUrl . '">' . $arrPage[$i] ."</a>";
					}*/
					$strPaging .= "<a href='".WEB_LINK."/product/page-lich-su-mua-hang-".$arrPage[$i]."#content'>".$arrPage[$i]."</a>";
				}
			}
	 	}
		return $strPaging;
	}
}
?>